﻿@model IEnumerable<VietPremier.EntityImageDestination>

@{
    ViewBag.Title = "Index";
    Layout = "~/Areas/AdminCP/Views/Shared/AdminLayout.cshtml";
}

<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-1.7.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery-ui-1.8.16.custom.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/custom/tables.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/cssAdmin/js/plugins/jquery.dataTables.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    jQuery(document).ready(function () {
        //LoadTable();
        $('#nofSuccess').hide(); // an thong bao
        $('#nofError').hide();
    });

    function alertMsg(msg) {
        $('#nofSuccess').hide();
        $('#nofError').show();
        $('#msgNofError').text(msg);
    }
    
    //Delete Category
    function DeleteRecord(id) {
        var answer = confirm("Do you want to Delete?")
        if (answer) {
            var getURL = '@Url.Action("Delete", "AdminImageDestination")';
            $.get(getURL, { "id": id }, function (data) {
                if (data == "Ok") {
                    $('#nofError').hide();
                    $('#nofSuccess').show();
                    $('#msgNofSuccess').text("Delete Record Ok");
                    window.location.href = '@Url.Action("Index", "AdminImageDestination")';
                }
                else {
                    $('#nofError').show();
                    $('#nofSuccess').hide();
                    $('#msgNofError').text("Cannot Delete Record");
                    alertMsg("Cannot delete, Please contact to website's technical");
                    //window.location.href = '@Url.Action("Index", "Error", new { errorMsg = "Can not delete!" })';
                }
            });
        }
        else {
            return false;
        }
        return false;
    }

</script>

<div class="maincontentinner">

    <ul class="maintabmenu">
        <li class="current"><a href="@Url.Action("Index", "AdminImageDestination")" >Quản lý hình ảnh điểm đến</a></li>
        <li><a href="@Url.Action("Insert", "AdminImageDestination", new { id = @ViewBag.IdDestination })" >Thêm mới hình ảnh điểm đến</a></li>
    </ul>
    <!--maintabmenu-->

    <div class="notification msgsuccess" style="display: none" id="nofSuccess">
        <a class="close"></a>
        <p id="msgNofSuccess">This is a success message.</p>
    </div>
    <!-- notification msgsuccess -->

    <div class="notification msgerror" style="display: none" id="nofError">
        <a class="close"></a>
        <p id="msgNofError">This is an error message.</p>
    </div>
    <!-- notification msgerror -->

    <div class="contenttitle radiusbottom0">
        <h2 class="table"><span>Danh sách hình ảnh của @ViewBag.DestinationName</span></h2>
    </div>
    <!--contenttitle-->

    <table cellpadding="0" cellspacing="0" border="0" class="stdtable" id="dyntable">
        <colgroup>
             <col class="con0" />
            <col class="con1" />
            <col class="con0" />
            <col class="con1" />
           
          
        </colgroup>
        <thead>
            <tr>
                <th class="head0">STT</th>           
                <th class="head1">Hình ảnh</th>  
                <th class="head0">vị trí</th>                
                <th class="head1">Thao tác</th>         

            </tr>
        </thead>
        <tfoot>
            <tr>
                <th class="head0">STT</th>           
                <th class="head1">Hình ảnh</th>  
                <th class="head0">vị trí</th>                
                <th class="head1">Thao tác</th>
            </tr>
        </tfoot>
        <tbody>
            @{
                int stt=0;
                foreach (var item in Model)
                {
                    stt++;
                <tr class="gradeX">
                    <td>@stt</td>                     
                    <td class="center">
                        @{
                    var imageFile = "~/Content/upload/destination/";
                    if (item.Image != null)
                    {
                        imageFile += @item.Image;
                    }
                    else
                    {
                        imageFile += "no-photo.jpg";
                    }
                        }

                        <img src= "@Url.Content(imageFile)" style="width:100px; height:100px" alt="" />
                    </td>
                       <td>@item.Position</td>
                        @{
                            VietPremier.EntityAdmin user = (VietPremier.EntityAdmin)Session["User"];
                            if (user.Type == "Admin" || user.Type == "Manager")
                            {
                                <td class="center">
                                    @Html.ActionLink("Edit", "Edit", new { id= @item.Id })
                                    &nbsp; 
                                    <a href="#" onclick="DeleteRecord(@item.Id)" >Delete</a>
                                  
                                </td>
                            }
                            else
                            {
                                 <td class="center">
                                    @Html.ActionLink("Edit", "Edit", new { id= @item.Id })
                                 
                                </td>
                            }
                        }                    
                </tr>
                }
            }
        </tbody>
    </table>

</div>
<!--maincontentinner-->
